from src.bean.config_column_enum import ConfigColumnEnum
from src.bean.increasing_param import IncreasingParam
from src.model.common.increasing import common_increasing
from src.model.model_common_util import get_old_model, get_df_by_path
from src.model.v1.v1_pre_handle import v1_pre_handle
from src.util.common_util import printx
from src.util.config_manager import ConfigManager
from src.util.file_selector_util import select_multi_file


def v1_increasing_train_entrance(config: ConfigManager, param: IncreasingParam = None):
    """
    param: 如果有增量参数就说明是从预测命令触发的增量
    """
    origin_file = ""
    if param is None:
        old_model = get_old_model(config)
        file_path_list = select_multi_file(config.get_config(ConfigColumnEnum.use_terminal.value),
                                           title="[增量训练]请选择增量的数据(包含正负样本，注意别选之前用过的)")
    else:
        old_model = param.model
        file_path_list = [param.file]
        origin_file = param.origin_file
    if old_model is None:
        return
    # 加载增量用到的文件
    df, files = get_df_by_path(file_path_list, origin_predict_file=origin_file)
    # 加载原模型的文件
    model_id = config.get_new_id()
    printx("[预处理]开始预处理")
    v1_pre_handle(df, model_id)
    common_increasing(config, model_id, files, df, old_model)
